home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/env python
-
- # mintInstall
- # No Copyright (What for?) Clem <root@linuxmint.com>
- #
- # This program is free software; you can redistribute it and/or
- # modify it under the terms of the GNU General Public License
- # as published by the Free Software Foundation; Version 2
- # of the License.
- #
- # This program is "inspired" by CNR and the idea of "one click install".
-
-
- import sys
- import apt
- import vte
- import fcntl
- import apt_pkg
- import vte
- import posix
- import string
-
- from apt.progress import OpProgress, FetchProgress, InstallProgress
-
- try:
- import pygtk
- pygtk.require("2.0")
- except:
- pass
- try:
- import gtk
- import gtk.glade
- import pango
- import os
- import gconf
- import locale
- import commands
- import threading
- import time
-
- except:
- print "You do not have all the dependencies!"
- sys.exit(1)
-
- gtk.gdk.threads_init()
-
-
- class GuiFetchProgress(FetchProgress):
- def __init__(self, progressbar):
- self.progress = progressbar
-
- def start(self):
- #print "start"
- #self.progress.set_fraction(0)
- pass
-
- def stop(self):
- #print "stop"
- pass
-
- def pulse(self):
- #FetchProgress.pulse(self)
- self.progress.set_text("Speed: %s/s" % apt_pkg.SizeToStr(self.currentCPS))
- percentage = self.currentBytes/self.totalBytes
- self.progress.set_fraction(percentage)
- os.system("echo " + str(percentage) + "> /usr/lib/linuxmint/mintInstall/tmp/progress")
- #while gtk.events_pending():
- # gtk.main_iteration()
- return True
-
- class TermInstallProgress(InstallProgress):
- def __init__(self, term, progressbar):
- self.term = term
- self.progressbar = progressbar
-
- # check for the child
- self.reaper = vte.reaper_get()
- self.reaper.connect("child-exited",self.child_exited)
- self.finished = False
-
- (read, write) = os.pipe()
- self.writefd=write
- self.status = os.fdopen(read, "r")
- fcntl.fcntl(self.status.fileno(), fcntl.F_SETFL,os.O_NONBLOCK)
- #print "read-fd: %s" % self.status.fileno()
- #print "write-fd: %s" % self.writefd
- self.read = ""
- #print "<--init"
-
- def child_exited(self,term, pid, status):
- #print "-->child exited"
- #print "child_exited: %s %s %s %s" % (self,term,pid,status)
- self.apt_status = posix.WEXITSTATUS(0)
- self.finished = True
- #print "<--child exited"
-
- #def startUpdate(self):
- # print "-->startupdate"
- # print "<--startupdate"
-
- def updateInterface(self):
- #print "-->updateInterface"
- if self.status != None:
- try:
- self.read += os.read(self.status.fileno(),1)
- except OSError, (errno,errstr):
- # resource temporarly unavailable is ignored
- if errno != 11:
- print errstr
- if self.read.endswith("\n"):
- s = self.read
- #print s
- (status, pkg, percent, status_str) = string.split(s, ":")
- #print "percent: %s %s" % (pkg, float(percent)/100.0)
- self.progressbar.set_fraction(float(percent)/100.0)
- self.progressbar.set_text(string.strip(status_str))
- self.read = ""
- #while gtk.events_pending():
- # gtk.main_iteration()
- #print "<--updateInterface"
-
- #def finishUpdate(self):
- #print "-->finishUpdate"
- #sys.stdin.readline()
- #print "<--finishUpdate"
-
- def run(self, pm):
- #print "-->run"
- #print "fork"
- env = ["VTE_PTY_KEEP_FD=%s"%self.writefd]
- #print env
- pid = self.term.forkpty(envv=env)
- if pid == 0:
- res = pm.DoInstall(self.writefd)
- #print res
- sys.exit(res)
- #print "After fork: %s " % pid
- while not self.finished:
- self.updateInterface()
- return self.apt_status
-
- class mintInstallExecuter(threading.Thread):
-
- def execute(self, command):
- #print "Executing: " + command
- os.system(command)
- ret = commands.getoutput("echo $?")
- return ret
-
- def run(self):
- global steps
- global progressbar
- global wTree
- global installation_terminal
- global installation_progressbar
- global download_progressbar
- global packages
-
- wTree.get_widget("main_button").hide()
- wTree.get_widget("cancel_button").hide()
-
- progressbar.set_text("Backing up your APT sources")
- self.execute("mv /etc/apt/sources.list /etc/apt/sources.list.mintbackup")
- self.execute("cp /usr/lib/linuxmint/mintInstall/sources.list /etc/apt/sources.list")
- self.execute("apt-get update")
- fraction = float(1)/float(steps+2)
- progressbar.set_fraction(fraction)
-
- for i in range(steps + 1):
- if (i > 0):
- openfile = open("/usr/lib/linuxmint/mintInstall/tmp/steps/"+str(i), 'r' )
- datalist = openfile.readlines()
- for j in range( len( datalist ) ):
- if (str.find(datalist[j], "TITLE") > -1):
- title = datalist[j][6:]
- progressbar.set_text(str.strip(title))
- if (str.find(datalist[j], "INSTALL") > -1):
- install = datalist[j][8:]
- install = str.strip(install)
- cache = apt.Cache()
- fprogress = GuiFetchProgress(download_progressbar)
- iprogress = TermInstallProgress(installation_terminal, installation_progressbar)
- pkg = cache[install]
- if not pkg.isInstalled:
- pkg.markInstall()
- cache.commit(fprogress, iprogress)
- if (str.find(datalist[j], "SOURCE") > -1):
- source = datalist[j][7:]
- source = source.rstrip()
- self.execute("echo \"" + source + "\" >> /etc/apt/sources.list")
- self.execute("apt-get update")
-
- fraction = float(i+1)/float(steps+2)
- progressbar.set_fraction(fraction)
-
- progressbar.set_text("Restoring your APT sources")
- self.execute("mv /etc/apt/sources.list.mintbackup /etc/apt/sources.list")
- self.execute("apt-get update")
- progressbar.set_fraction(1)
-
- progressbar.set_text("Finished")
- #wTree.get_widget("main_button").hide()
- #wTree.get_widget("cancel_button").set_label("Close")
- # Check that all packages are now installed
- txt_packages = ""
- allPackagesAreInstalled = True
- for package in packages:
- number_installed = commands.getoutput("aptitude search " + package + " | grep ^i | wc -l")
- if (number_installed == "0"):
- txt_packages = package + " (not installed)\n"
- allPackagesAreInstalled = False
- else:
- txt_packages = package + " (installed)\n"
- txt_packages = str.strip(txt_packages)
- dialog_gladefile = "/usr/lib/linuxmint/mintInstall/mintInstall.glade"
- dialog_wTree = gtk.glade.XML(dialog_gladefile,"message_dialog")
-
- #Set a new style for the status
- HeadingStyle = pango.AttrList()
- attr = pango.AttrSize(13000,0,-1)
- HeadingStyle.insert(attr)
- attr = pango.AttrForeground(24576,34816,41728,0,-1)
- HeadingStyle.insert(attr)
- dialog_wTree.get_widget("txt_status").set_attributes(HeadingStyle)
-
- if (allPackagesAreInstalled):
- dialog_wTree.get_widget("txt_status").set_text("Success")
- else:
- dialog_wTree.get_widget("txt_status").set_text("Failure")
-
- dialog_wTree.get_widget("txt_packages_status").set_text(txt_packages)
-
- button = dialog_wTree.get_widget("ok_button")
- button.connect("clicked",gtk.main_quit)
- dialog = dialog_wTree.get_widget("message_dialog")
- dialog.set_parent(wTree.get_widget("main_window"))
- dialog.show()
-
- class mintInstallWindow:
- """This is the main class for the application"""
-
- def __init__(self, mintFile):
- global steps
- global progressbar
- global wTree
- global installation_terminal
- global installation_progressbar
- global download_progressbar
- global packages
-
- self.mintFile = mintFile
-
- #Make tmp folder
- os.system("mkdir -p /usr/lib/linuxmint/mintInstall/tmp")
-
- #Clean tmp files
- os.system("rm -rf /usr/lib/linuxmint/mintInstall/tmp/*")
-
- #Decompress file
- os.system("cp " + mintFile + " /usr/lib/linuxmint/mintInstall/tmp/file.mint")
- os.system("tar zxf /usr/lib/linuxmint/mintInstall/tmp/file.mint -C /usr/lib/linuxmint/mintInstall/tmp/")
-
- #Extract the name
- self.name = commands.getoutput("cat /usr/lib/linuxmint/mintInstall/tmp/name")
- self.name = str.strip(self.name)
-
- #Extract the description
- self.description = commands.getoutput("cat /usr/lib/linuxmint/mintInstall/tmp/description")
- self.description = str.strip(self.description)
-
- #Extract the version
- self.version = commands.getoutput("cat /usr/lib/linuxmint/mintInstall/tmp/version")
- self.version = str.strip(self.version)
-
- #Extract the number of steps
- steps = int(commands.getoutput("ls -l /usr/lib/linuxmint/mintInstall/tmp/steps/ | wc -l"))
- steps = steps -1
- self.pulse = 1/steps
-
- #Extract repositories and packages
- self.repositories = []
- packages = []
- for i in range(steps + 1):
- if (i > 0):
- openfile = open("/usr/lib/linuxmint/mintInstall/tmp/steps/"+str(i), 'r' )
- datalist = openfile.readlines()
- for j in range( len( datalist ) ):
- if (str.find(datalist[j], "INSTALL") > -1):
- install = datalist[j][8:]
- install = str.strip(install)
- packages.append(install)
- if (str.find(datalist[j], "SOURCE") > -1):
- source = datalist[j][7:]
- source = source.rstrip()
- self.repositories.append(source)
- #openfile.close()
-
- #Set the Glade file
- self.gladefile = "/usr/lib/linuxmint/mintInstall/mintInstall.glade"
- wTree = gtk.glade.XML(self.gladefile,"main_window")
-
- #Set a new style for the name
- HeadingStyle = pango.AttrList()
- attr = pango.AttrSize(13000,0,-1)
- HeadingStyle.insert(attr)
- attr = pango.AttrForeground(24576,34816,41728,0,-1)
- HeadingStyle.insert(attr)
- wTree.get_widget("txt_name").set_attributes(HeadingStyle)
-
- #Create our dictionay and connect it
- dic = {"on_main_button_clicked" : (self.MainButtonClicked),
- "on_cancel_button_clicked" : (gtk.main_quit) }
- wTree.signal_autoconnect(dic)
-
- #Fill in the GUI with information from the mintFile
- wTree.get_widget("txt_name").set_text(self.name + " " + self.version)
- wTree.get_widget("txt_description").set_text(self.description)
- txt_packages = ""
- packages.sort()
- self.needToInstallSomething = False
- for package in packages:
- number_installed = commands.getoutput("aptitude search " + package + " | grep ^i | wc -l")
- if (number_installed == "0"):
- txt_packages = package + " (not installed)\n"
- self.needToInstallSomething = True
- else:
- txt_packages = package + " (installed)\n"
- txt_packages = str.strip(txt_packages)
- wTree.get_widget("txt_packages").set_text(txt_packages)
- txt_repositories = ""
- self.repositories.sort()
- for repository in self.repositories:
- txt_repositories = repository + "\n"
- txt_repositories = str.strip(txt_repositories)
- wTree.get_widget("main_button").set_sensitive(self.needToInstallSomething)
- wTree.get_widget("image_icon").set_from_file("/usr/lib/linuxmint/mintInstall/tmp/icon")
- wTree.get_widget("txt_repositories").set_text(txt_repositories)
- progressbar = wTree.get_widget("progressbar1")
- fraction = 0
- progressbar.set_fraction(fraction)
-
- download_progressbar = wTree.get_widget("download_progressbar")
-
- # Set the installation box
- box = wTree.get_widget("installation_box")
- installation_terminal = vte.Terminal()
- installation_terminal.set_background_transparent(True)
- installation_terminal.show()
- box.pack_start(installation_terminal)
- installation_progressbar = gtk.ProgressBar()
- installation_progressbar.show()
- box.pack_start(installation_progressbar)
-
- def MainButtonClicked(self, widget):
- executer = mintInstallExecuter()
- executer.start()
- return True
-
- class InstanceDialog:
- def __init__(self):
-
- #Set the Glade file
- self.gladefile = "/usr/lib/linuxmint/mintInstall/mintInstall.glade"
-
- def run(self,message):
- """This function will show the Instance Dialog"""
- self.wTree = gtk.glade.XML(self.gladefile, "dialog3")
- #Get the actual dialog widget
- self.dlg = self.wTree.get_widget("dialog3")
- self.wTree.get_widget("label164").set_label((message))
- #run the dialog and store the response
- self.result = self.dlg.run()
- #we are done with the dialog, destroy it
- self.dlg.destroy()
- #return the result
- return self.result
-
-
- if __name__ == "__main__":
- if (os.path.exists("/etc/apt/sources.list.mintbackup")):
- os.system("mv /etc/apt/sources.list.mintbackup /etc/apt/sources.list")
- os.system("apt-get update")
- warnDlg = gtk.Dialog(title="MintInstall", parent=None, flags=0, buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK))
- warnDlg.vbox.set_spacing(10)
- labelSpc = gtk.Label(" ")
- warnDlg.vbox.pack_start(labelSpc)
- labelSpc.show()
- warnText = ("<b>Your APT sources were corrupted.</b>")
- infoText = ("Your APT sources were not correctly restored after you last ran mintInstall. They now have been restored.")
- label = gtk.Label(warnText)
- lblInfo = gtk.Label(infoText)
- label.set_use_markup(True)
- lblInfo.set_use_markup(True)
- warnDlg.vbox.pack_start(label)
- warnDlg.vbox.pack_start(lblInfo)
- label.show()
- lblInfo.show()
- response = warnDlg.run()
- if response == gtk.RESPONSE_OK :
- warnDlg.destroy()
- #gtk.main_quit()
- sys.exit(0)
- else:
- os.system("rm -rf /var/lib/dpkg/lock")
- os.system("rm -rf /var/lib/apt/lists/lock")
- os.system("rm -rf /var/cache/apt/archives/lock")
- mainwin = mintInstallWindow(sys.argv[1])
- gtk.main()
-
-